package com.letwal.cmcvnd.mywallet

import android.annotation.SuppressLint
import android.view.View
import androidx.lifecycle.ViewModel
import androidx.recyclerview.widget.LinearLayoutManager
import com.letwal.cmcvnd.base.BaseActivity
import com.letwal.cmcvnd.adata.RevDataWallet
import com.letwal.cmcvnd.databinding.ActivityAddWalletBinding
import com.letwal.cmcvnd.enums.PageTagEnum
import com.letwal.cmcvnd.extend.*
import com.letwal.cmcvnd.mywallet.adapter.AddWalletAdapter

/** 创建币页 */
@SuppressLint("CustomSplashScreen")
class AddWalletActivity : BaseActivity() {

    //布局binding
    private lateinit var mActivityBinding: ActivityAddWalletBinding

    //适配器
    private lateinit var mAddWalletAdapter: AddWalletAdapter

    override fun onBindingViewModel(): List<ViewModel> {
        val list = mutableListOf<ViewModel>()
        return list
    }

    override fun onBindingViewTag(): String {
        return PageTagEnum.my_wallet.name.uppercase()
    }

    override fun onBindingContentView(): View {
        mActivityBinding =
            ActivityAddWalletBinding.inflate(layoutInflater)
        return mActivityBinding.root
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onContentViewBinded() {
        try {
            //初始化适配器
            val testList = mutableListOf<RevDataWallet>()
            for (index in 0 until 10) {
                testList.add(RevDataWallet(name = "ETH", detail = "text $index"))
            }
            mAddWalletAdapter = AddWalletAdapter(testList)
            mAddWalletAdapter.setItemClickListener { position ->
                testList.forEachIndexed { index, revDataWallet ->
                    if (index == position) {
                        revDataWallet.checked = !revDataWallet.checked
                    }
                }
                mAddWalletAdapter.notifyDataSetChanged()
            }

            mActivityBinding.listAddWallet.layoutManager = LinearLayoutManager(this)
            mActivityBinding.listAddWallet.adapter = mAddWalletAdapter

            //点击确定
            mActivityBinding.textAddWalletAdd.setOnClickListener {

            }

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

}